home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Halma 1.1.source Folder / Halma ƒ / Halma code ƒ / halma board size.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  8.3 KB  |  308 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        halma board size.c
  4.  
  5. Purpose:    This module handles doing the "board size" window.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "halma board size.h"
  25. #include "environment.h"
  26. #include "util.h"
  27. #include "prefs.h"
  28. #include "program globals.h"
  29.  
  30. /* internal procedures for halma board size.c only */
  31. void SetupTheBoardSizeWindow(WindowDataHandle theData);
  32. void ShutDownTheBoardSizeWindow(WindowDataHandle theData);
  33. void InitializeTheBoardSizeWindow(WindowDataHandle theData);
  34. void OpenTheBoardSizeWindow(WindowDataHandle theData);
  35. void IdleInBoardSizeWindow(WindowDataHandle theData);
  36. void KeyPressedInBoardSizeWindow(WindowDataHandle theData, unsigned char theChar);
  37. void MouseClickedInBoardSizeWindow(WindowDataHandle theData, Point thePoint);
  38. void DisposeTheBoardSizeWindow(WindowDataHandle theData);
  39. void ActivateTheBoardSizeWindow(WindowDataHandle theData);
  40. void DeactivateTheBoardSizeWindow(WindowDataHandle theData);
  41. void DrawTheBoardSizeWindow(WindowDataHandle theData, short theDepth);
  42.  
  43. static    short            gOldForegroundTime;        /* stored foreground wait time */
  44. static    PicHandle        gSliderPict;
  45.  
  46. short BoardSizeWindowDispatch(WindowDataHandle theData, short theMessage,
  47.     unsigned long misc)
  48. {
  49.     short            theDepth;
  50.     unsigned char    theChar;
  51.     Point            thePoint;
  52.     
  53.     switch (theMessage)
  54.     {
  55.         case kNull:
  56.             IdleInBoardSizeWindow(theData);
  57.             return kSuccess;
  58.             break;
  59.         case kUpdate:
  60.             theDepth=misc&0x7fff;
  61.             DrawTheBoardSizeWindow(theData, theDepth);
  62.             return kSuccess;
  63.             break;
  64.         case kInitialize:
  65.             InitializeTheBoardSizeWindow(theData);
  66.             return kSuccess;
  67.             break;
  68.         case kOpen:
  69.             OpenTheBoardSizeWindow(theData);
  70.             return kSuccess;
  71.             break;
  72.         case kKeydown:
  73.             theChar=misc&charCodeMask;
  74.             KeyPressedInBoardSizeWindow(theData, theChar);
  75.             return kSuccess;
  76.             break;
  77.         case kMousedown:
  78.              thePoint.h=(misc>>16)&0x7fff;
  79.              thePoint.v=misc&0x7fff;
  80.              MouseClickedInBoardSizeWindow(theData, thePoint);
  81.              return kSuccess;
  82.              break;
  83.          case kActivate:
  84.              ActivateTheBoardSizeWindow(theData);
  85.              return kSuccess;
  86.              break;
  87.          case kDeactivate:
  88.              DeactivateTheBoardSizeWindow(theData);
  89.              return kSuccess;
  90.              break;
  91.         case kStartup:
  92.             SetupTheBoardSizeWindow(theData);
  93.             return kSuccess;
  94.             break;
  95.         case kDispose:
  96.             DisposeTheBoardSizeWindow(theData);
  97.             return kSuccess;
  98.             break;
  99.         case kShutdown:
  100.             ShutDownTheBoardSizeWindow(theData);
  101.             return kSuccess;
  102.             break;
  103.     }
  104.     
  105.     return kFailure;
  106. }
  107.  
  108. void SetupTheBoardSizeWindow(WindowDataHandle theData)
  109. {
  110.     unsigned char    *titleStr="\pBoard Size";
  111.     
  112.     (**theData).maxDepth=1;
  113.     (**theData).windowWidth=154;
  114.     (**theData).windowHeight=120;
  115.     (**theData).windowType=noGrowDocProc;
  116.     (**theData).hasCloseBox=TRUE;
  117.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)titleStr, titleStr[0]+1);
  118.     
  119.     gSliderPict=0L;
  120. }
  121.  
  122. void ShutDownTheBoardSizeWindow(WindowDataHandle theData)
  123. {
  124.     gSliderPict=ReleaseThePict(gSliderPict);
  125. }
  126.  
  127. void InitializeTheBoardSizeWindow(WindowDataHandle theData)
  128. {
  129.     (**theData).initialTopLeft.h =
  130.         screenBits.bounds.left + (((screenBits.bounds.right -
  131.         screenBits.bounds.left) - (**theData).windowWidth) / 2);
  132.     (**theData).initialTopLeft.v =
  133.         screenBits.bounds.top + (((screenBits.bounds.bottom -
  134.         screenBits.bounds.top) - (**theData).windowHeight) / 3);
  135. }
  136.  
  137. void OpenTheBoardSizeWindow(WindowDataHandle theData)
  138. {
  139.     (**theData).offscreenNeedsUpdate=TRUE;
  140. }
  141.  
  142. void IdleInBoardSizeWindow(WindowDataHandle theData)
  143. {
  144. }
  145.  
  146. void KeyPressedInBoardSizeWindow(WindowDataHandle theData, unsigned char theChar)
  147. {
  148.     switch (theChar)
  149.     {
  150.         case 0x0d:
  151.         case 0x03:
  152.         case 0x1b:
  153.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  154.             break;
  155.     }
  156. }
  157.  
  158. void MouseClickedInBoardSizeWindow(WindowDataHandle theData, Point thePoint)
  159. {
  160.     Point            startMouseLoc, tempMouseLoc;
  161.     Rect            sliderRect, wholeRect;
  162.     Point            temp, startPt, lastPt;
  163.     
  164.     SetRect(&sliderRect, ROW_LEFT-4, ROW_TOP+5+(9-gNumRows)*12,
  165.         ROW_LEFT+18, ROW_TOP+15+(9-gNumRows)*12);
  166.     SetRect(&wholeRect, ROW_LEFT-4, ROW_TOP+4, ROW_LEFT+18, ROW_TOP+74);
  167.     GetMouse(&startMouseLoc);
  168.     if (PtInRect(startMouseLoc, &sliderRect))
  169.     {
  170.         gNumRows=0;
  171.         startPt.h=sliderRect.left-1;
  172.         startPt.v=sliderRect.top;
  173.         lastPt=temp=startPt;
  174.         while (StillDown())
  175.         {
  176.             GetMouse(&tempMouseLoc);
  177.             temp.v=startPt.v+tempMouseLoc.v-startMouseLoc.v;
  178.             if (temp.v<wholeRect.top)
  179.                 temp.v=wholeRect.top;
  180.             else if (temp.v>wholeRect.bottom-10)
  181.                 temp.v=wholeRect.bottom-10;
  182.             if (lastPt.v!=temp.v)
  183.             {
  184.                 gNumRows=-temp.v;
  185.                 (**theData).offscreenNeedsUpdate=TRUE;
  186.                 UpdateTheWindow((ExtendedWindowDataHandle)theData);
  187.             }
  188.             lastPt=temp;
  189.         }
  190.         temp.v=wholeRect.top+((temp.v-wholeRect.top+6)/12)*12;
  191.         if (lastPt.v!=temp.v)
  192.         {
  193.             gNumRows=-temp.v;
  194.             (**theData).offscreenNeedsUpdate=TRUE;
  195.             UpdateTheWindow((ExtendedWindowDataHandle)theData);
  196.         }
  197.         gNumRows=9-((temp.v-wholeRect.top)/12);
  198.     }
  199.     else
  200.     {
  201.         SetRect(&sliderRect, COL_LEFT-4, COL_TOP+5+(9-gNumColumns)*12,
  202.             COL_LEFT+18, COL_TOP+15+(9-gNumColumns)*12);
  203.         SetRect(&wholeRect, COL_LEFT-4, COL_TOP+4, COL_LEFT+18, COL_TOP+74);
  204.         GetMouse(&startMouseLoc);
  205.         if (PtInRect(startMouseLoc, &sliderRect))
  206.         {
  207.             gNumColumns=0;
  208.             startPt.h=sliderRect.left-1;
  209.             startPt.v=sliderRect.top;
  210.             lastPt=temp=startPt;
  211.             while (StillDown())
  212.             {
  213.                 GetMouse(&tempMouseLoc);
  214.                 temp.v=startPt.v+tempMouseLoc.v-startMouseLoc.v;
  215.                 if (temp.v<wholeRect.top)
  216.                     temp.v=wholeRect.top;
  217.                 else if (temp.v>wholeRect.bottom-10)
  218.                     temp.v=wholeRect.bottom-10;
  219.                 if (lastPt.v!=temp.v)
  220.                 {
  221.                     gNumColumns=-temp.v;
  222.                     (**theData).offscreenNeedsUpdate=TRUE;
  223.                     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  224.                 }
  225.                 lastPt=temp;
  226.             }
  227.             temp.v=wholeRect.top+((temp.v-wholeRect.top+6)/12)*12;
  228.             if (lastPt.v!=temp.v)
  229.             {
  230.                 gNumColumns=-temp.v;
  231.                 (**theData).offscreenNeedsUpdate=TRUE;
  232.                 UpdateTheWindow((ExtendedWindowDataHandle)theData);
  233.             }
  234.             gNumColumns=9-((temp.v-wholeRect.top)/12);
  235.         }
  236.     }
  237. }
  238.  
  239. void DisposeTheBoardSizeWindow(WindowDataHandle theData)
  240. {
  241. }
  242.  
  243. void ActivateTheBoardSizeWindow(WindowDataHandle theData)
  244. {
  245.     gOldForegroundTime=gForegroundWaitTime;
  246.     gForegroundWaitTime=0;
  247. }
  248.  
  249. void DeactivateTheBoardSizeWindow(WindowDataHandle theData)
  250. {
  251.     gForegroundWaitTime=gOldForegroundTime;
  252. }
  253.  
  254. void DrawTheBoardSizeWindow(WindowDataHandle theData, short theDepth)
  255. {
  256.     Rect            theRect, theOtherRect;
  257.     short            i;
  258.     GrafPtr            curPort;
  259.     
  260.     GetPort(&curPort);
  261.     EraseRect(&(curPort->portRect));
  262.     
  263.     SetRect(&theRect, ROW_LEFT, ROW_TOP, ROW_LEFT+12, ROW_TOP+79);
  264.     theOtherRect=theRect;
  265.     OffsetRect(&theOtherRect, COL_LEFT-ROW_LEFT, 0);
  266.     FrameRoundRect(&theRect, 10, 9);
  267.     FrameRoundRect(&theOtherRect, 10, 9);
  268.     InsetRect(&theRect, 2, 2);
  269.     InsetRect(&theOtherRect, 2, 2);
  270.     FrameRoundRect(&theRect, 7, 7);
  271.     FrameRoundRect(&theOtherRect, 7, 7);
  272.     InsetRect(&theRect, 1, 1);
  273.     InsetRect(&theOtherRect, 1, 1);
  274.     FillRoundRect(&theRect, 7, 7, gray);
  275.     FillRoundRect(&theOtherRect, 7, 7, gray);
  276.     TextSize(9);
  277.     TextMode(srcOr);
  278.     TextFont(geneva);
  279.     TextFace(0);
  280.     for (i=0; i<=5; i++)
  281.     {
  282.         MoveTo(ROW_LEFT-3, ROW_TOP+9+i*12);
  283.         Line(-3, 0);
  284.         MoveTo(COL_LEFT-3, COL_TOP+9+i*12);
  285.         Line(-3, 0);
  286.         MoveTo(ROW_LEFT-16, ROW_TOP+13+i*12);
  287.         DrawChar('9'-i);
  288.         MoveTo(COL_LEFT-16, COL_TOP+13+i*12);
  289.         DrawChar('9'-i);
  290.     }
  291.     if (gNumRows>0)
  292.         gSliderPict=DrawThePicture(gSliderPict, sliderID, ROW_LEFT-5,
  293.             ROW_TOP+4+(9-gNumRows)*12);
  294.     else
  295.         gSliderPict=DrawThePicture(gSliderPict, sliderID, ROW_LEFT-5, -gNumRows);
  296.     
  297.     if (gNumColumns>0)
  298.         gSliderPict=DrawThePicture(gSliderPict, sliderID, COL_LEFT-5,
  299.             COL_TOP+4+(9-gNumColumns)*12);
  300.     else
  301.         gSliderPict=DrawThePicture(gSliderPict, sliderID, COL_LEFT-5, -gNumColumns);
  302.     
  303.     MoveTo(ROW_LEFT-13, ROW_TOP-10);
  304.     DrawString("\pRows");
  305.     MoveTo(COL_LEFT-18, COL_TOP-10);
  306.     DrawString("\pColumns");
  307. }
  308.